package util;

import java.util.Vector ;

/**
 * this represents a discrete graph, a discrete mapping from the x axis to the y axis.
 *
 * @author idan
 */
public class Statistics
{
	private Vector<Integer> values ;

	/**
	 * @param quantum range of the x axis is from 0 to quantum-1.
	 * @pre quantum >= 0.
	 * @post getQuantum() = quantum.
	 * @post for all x, s.get(x) == 0.
	 */
	public Statistics(final int quantum)
	{
		this.values = new Vector<Integer>() ;
		for (int i = 0 ; i < quantum ; i++)
		{
			this.values.add(0) ;
		}
	}

	/**
	 * @param x point on the x axis.
	 * @return y value at point x.
	 * @pre 0 <= x < getQuantum().
	 */
	public int get(final int x)
	{
		return this.values.get(x) ;
	}

	/**
	 * @return amount of values on the x axis.
	 */
	public int getQuantum()
	{
		return this.values.size() ;
	}

	/**
	 * @param x point at which to increment y value.
	 * @pre 0 <= x < getQuantum().
	 * @post get(x) = get(x)@pre + 1.
	 */
	public void increment(final int x)
	{
		int y = this.values.get(x) ;
		this.values.set(x, y+1) ;
	}

	/**
	 * @param x point on the x axis.
	 * @param y y value at point x.
	 * @pre 0 <= x < getQuantum().
	 * @post get(x) = y.
	 */
	public void set(final int x, final int y)
	{
		this.values.set(x, y) ;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return this.values.toString() ;
	}
}
